package com.example.springboot_blog.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.springboot_blog.dao.ArticleDao;
import com.example.springboot_blog.dao.CommentDao;
import com.example.springboot_blog.domain.Article;
import com.example.springboot_blog.domain.Comment;
import com.example.springboot_blog.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author 白草风归
 */
@Service
public class CommentServiceImpl extends ServiceImpl<CommentDao,Comment> implements CommentService {
    @Autowired
    private CommentDao commentDao;
    @Autowired
    private ArticleDao articleDao;
    @Override
    public List<Comment> selectCommentList(Integer id) {
        return commentDao.selectCommentByArticleId(id);
    }

    /**
     * @Param:a
     * @Rerrn:a
     * 添加评论,只能添加评论
     */
    public void addComment(Integer id, String username, String body){
        Comment comment = new Comment();
        Article articles = articleDao.selectById(id);
        comment.setUsername(username);
        comment.setBody(body);
        comment.setCreate_date(new Date());
        comment.setArticle_id(articles.getId());
        commentDao.insert(comment);
    }

}
